package connection;

import java.security.SecureRandom;

/**
 * 
 * @author Julian Beisert
 * @version 1.0
 */
public class Session {

	private int _serverSession;
	private int _clientSession;
	private static Session _instance;

	private Session() {

	}

	/**
	 * generate Session
	 */
	private void generateSession() {
		SecureRandom random = new SecureRandom();
		this._serverSession = random.nextInt(8000) + 1999;
	}

	/**
	 * 
	 * @return Server Session
	 */
	public int getServerSession() {
		return this._serverSession;
	}

	/**
	 * 
	 * @return Client Session
	 */
	public int getClientSession() {
		return this._clientSession;
	}

	/**
	 * 
	 * @param session
	 *            Client Session
	 */
	public void setClientSession(int session) {
		this._clientSession = session;
	}

	/**
	 * 
	 * @param session
	 *            Session extract from TAN
	 * @return boolean if Session is equal
	 */
	public boolean checkSession(int session) {
		boolean check = false;
		if (this._serverSession == session) {
			check = true;
		}
		return check;
	}

	/**
	 * 
	 * @return Singleton Session Object
	 */
	public static Session getInstance() {
		if (_instance == null) {
			_instance = new Session();
			_instance.generateSession();
			;
		}
		return _instance;

	}
}
